// 存储的入口

import { legacy_createStore as createStore, applyMiddleware, combineReducers } from "redux"
// import { configureStore, createSlice } from "reduxjs/toolkit"
import thunk from 'redux-thunk'
import axios from "axios"
import indexReducer from "./index";
import userReducer from "./user";

const reducer = combineReducers({
  index: indexReducer,
  user: userReducer
})
const clientAxios = axios.create({
  baseURL: "/"
});
const serverAxios = axios.create({
  baseURL: "http://localhost:9090/"
});

// 创建store
export const getServerStore = () => {
  // 服务端的store
  return createStore(reducer, applyMiddleware(thunk.withExtraArgument(serverAxios)));
}

export const getClientStore = () => {
  // 客户端的store
  // 通过window.__context获取store初始化的值
  const defaultState = window.__context ? window.__context : {}
  return createStore(reducer, defaultState, applyMiddleware(thunk.withExtraArgument(clientAxios)));
}